package com.eastone.user.serverapi.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.eastone.user.serverapi.dao.InfoRoleDao;
import com.eastone.user.serverapi.model.InfoRole;
import com.eastone.user.serverapi.service.InfoRoleService;
import com.yjx.framework.cache.ServiceResultCodeCache;

import com.yjx.framework.model.ServiceResult;

@Service("infoRoleService")
public class InfoRoleServiceImpl implements InfoRoleService {
	@Autowired
	private InfoRoleDao infoRoleDao;
	private static ServiceResultCodeCache resultCode = ServiceResultCodeCache.getInstance();

	@Override
	public InfoRole get(int id) {
		return infoRoleDao.get(id);
	}

	@Override
	public ServiceResult<String> add(InfoRole infoRole) {
		ServiceResult<String> serviceResult = new ServiceResult<String>();
		int result = infoRoleDao.add(infoRole);
		if (result == 1) {
			serviceResult.setCode(resultCode.get("common.sucess"));
		} else {
			serviceResult.setCode(resultCode.get("common.fail"));
		}
		return serviceResult;
	}

	@Override
	public ServiceResult<String> addSelective(InfoRole infoRole) {
		ServiceResult<String> serviceResult = new ServiceResult<String>();
		int result = infoRoleDao.addSelective(infoRole);
		if (result == 1) {
			serviceResult.setCode(resultCode.get("common.sucess"));
		} else {
			serviceResult.setCode(resultCode.get("common.fail"));
		}
		return serviceResult;
	}

	@Override
	public ServiceResult<String> update(InfoRole infoRole) {
		ServiceResult<String> serviceResult = new ServiceResult<String>();
		int result = infoRoleDao.update(infoRole);
		if (result == 1) {
			serviceResult.setCode(resultCode.get("common.sucess"));
		} else {
			serviceResult.setCode(resultCode.get("common.fail"));
		}
		return serviceResult;
	}

	@Override
	public ServiceResult<String> updateSelective(InfoRole infoRole) {
		ServiceResult<String> serviceResult = new ServiceResult<String>();
		int result = infoRoleDao.updateSelective(infoRole);
		if (result == 1) {
			serviceResult.setCode(resultCode.get("common.sucess"));
		} else {
			serviceResult.setCode(resultCode.get("common.fail"));
		}
		return serviceResult;
	}

	@Override
	public ServiceResult<String> delete(InfoRole infoRole) {
		ServiceResult<String> serviceResult = new ServiceResult<String>();
		int result = infoRoleDao.delete(infoRole);
		if (result == 1) {
			serviceResult.setCode(resultCode.get("common.sucess"));
		} else {
			serviceResult.setCode(resultCode.get("common.fail"));
		}
		return serviceResult;
	}

	@Override
	public List<InfoRole> getList(String name, String code, int pageNo, int pageSize) {
		return infoRoleDao.getList(name, code, pageNo, pageSize);
	}

	@Override
	public int getCount(String name, String code) {
		return infoRoleDao.getCount(name, code);
	}
}
